package com.intellagric.controller.module.agriecom_produce_param_value;

import com.intellagric.agriecom.module.agriecom_produce_param_value.ParamValueService;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.AgriecomProduceParamValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.UUID;

@Controller
@RequestMapping("/paramValue")
public class ProduceParamValueController {
    @Autowired
    private ParamValueService service;



    /**
     * 根据id查询
     * @param id
     * @return
     */
    @RequestMapping("/getById")
    @ResponseBody
    public AgriecomProduceParamValue findParamById(@RequestParam String id){
        return service.selectParamValueById(id);
    }

    /**
     * 添加产品参数
     * @param produceParamValue
     * @return
     */
    @RequestMapping("/addParamValue")
    @ResponseBody
    public ResponseMessage addParamValue(AgriecomProduceParamValue produceParamValue){
        String id= UUID.randomUUID().toString().replaceAll("-","");
        if(produceParamValue!=null){
            produceParamValue.setId(id);
            service.addParamValue(produceParamValue);
        }

        return ResponseMessage.fail();
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @RequestMapping("delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return service.deleteParamValueById(id);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @RequestMapping(value="deleteAll",method = RequestMethod.GET)
    @ResponseBody
    public LayuiDataGridResult deleteAll(@RequestParam(name = "ids[]") String[] ids) {
        return service.batchDelete(ids);
    }
    /**
     * 修改信息
     * @param produceParamValue
     * @return
     */
    @RequestMapping("edit")
    @ResponseBody
    public ResponseMessage edit(AgriecomProduceParamValue produceParamValue){
        if(produceParamValue!=null)
            return service.updateParamValueByVo(produceParamValue);
        return ResponseMessage.fail();
    }

    /**
     * 分页列表
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public LayuiDataGridResult query(@RequestParam(value="page",defaultValue = "1") int page, @RequestParam(value = "limit",defaultValue = "10") int limit){
        return service.getParamValueList(page,limit);
    }

    /**
     * 获取分类分页
     * @param page
     * @param limit
     * @param categoryId
     * @return
     */
    @RequestMapping("getListByParam")
    @ResponseBody
    public LayuiDataGridResult getListByParam(@RequestParam(value="page",defaultValue = "1") int page, @RequestParam(value = "limit",defaultValue = "10") int limit, String categoryId){
        return service.getParamListByParam(categoryId,page,limit);
    }


    @RequestMapping("getListByKeyword")
    @ResponseBody
    public LayuiDataGridResult getListByKeyword(@RequestParam(value="page",defaultValue = "1") int page, @RequestParam(value = "limit",defaultValue = "10") int limit,String keyword){
        return service.getListByKeyword(page,limit,keyword);
    }

}
